<?php
$url = "http://211.82.48.36/img/captcha.jpg";


$curl = curl_init();
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_ACCEPT_ENCODING, "gzip,deflate");

$return_content = curl_exec($curl);
curl_close($curl);
preg_match('/Set-Cookie:(.*);/iU', $return_content, $str); //正则匹配
$cookie = $str[1]; //获得COOKIE（SESSIONID）

list($header, $body) = explode("\r\n\r\n", $return_content);

header('Content-Type:application/json; charset=utf-8');
$arr = array('err' => 0, 'captcha_url' => 'data:image/jpg;base64,' . base64_encode($body), "session" => $cookie);

exit(json_encode($arr));
